<template>
<div>
    <h2 style="text-align: center;">理财项目列表</h2>
    <FinanCommon v-slot="info">
        <a href="#" @click="DeleteFinanInfo(info.id)">删除</a>
        &nbsp;
        <a href="#" @click="UpdateFinanInfo(info.id)">修改</a>
    </FinanCommon>

</div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { useRouter } from 'vue-router';
import FinanCommon from '../Finans//FinanCommon.vue'

//创建路由对象
const router=useRouter();


//删除数据
const DeleteFinanInfo=(Fid:number)=>{
    if(confirm('你确定要删除吗?'))
    {
        axios.delete("https://localhost:44321//api/Finans/DeleteFinanInfo",
            {
                params:{
                    Fid:Fid
                }
            }
        )
        .then(res=>{
            if(res.data>0)
            {
                alert('删除成功');
                location.reload();
            }
            else if(res.data==-1)
            {
                alert('该项目已经有人理财,不能删除');
            }
            else
            {
                alert('删除失败!!!!');
            }
        })
    }
}

//修改数据
const UpdateFinanInfo=(Fid:number)=>{
    router.push({
        name:"EditFinaninfo",
        params:{
            Fid:Fid
        }
    })
}
</script>
